![]() |
| Create Table using AS in DB2 for i |
We can create a table from the result of a SELECT statement. We can use CREATE TABLE AS statement to create such type of tables in DB2.
Example 1:
CREATE TABLE PF2 AS
(SELECT * FROM PF1)
WITH NO DATA
Here, we created table named PF2 same as PF1 by using AS keyword and selected all the columns from the PF1 table. Also, we must need to specify whether we need data or not from the selected table into the new table that is to be created.
Example 2:
CREATE TABLE PF2 AS
(SELECT * FROM PF1)
WITH DATA
Example 3:
CREATE TABLE PF2 AS
(SELECT Empid, empname FROM PF1)
WITH NO DATA
Example 4:
CREATE TABLE PF2 AS
(SELECT Empid, empname FROM PF1)
WITH DATA
Example 5:
CREATE TABLE PF2 AS
(SELECT Empid, empname FROM PF1 WHERE MANAGERID = 1)
WITH DATA
Additional information on using CREATE TABLE AS statement in DB2 for i
CREATE TABLE PF2 AS
(SELECT Empid, empname FROM PF1)
WITH NO DATA INCLUDING IDENTITY
If PF1 would have the identity column then we can also copy the identity column using the INCLUDING IDENTITY option in the CREATE TABLE AS statement.
